package ca.camosun.proximity;

import java.util.Comparator;
import java.util.Date;

public class SavedPerson implements Comparable<SavedPerson> {
	private String name;
	private String deviceAddress;
	private Date lastSeen;

	public SavedPerson(String inName, String inDeviceAddress) {
		name = inName;
		deviceAddress = inDeviceAddress;
		lastSeen = new Date();
	}

	public String getName() {
		return name;
	}

	public String getAddress() {
		return deviceAddress;
	}
	
	public Date getLastTimeSeen() {
		return lastSeen;
	}

	public void setName(String inName) {
		name = inName;
	}
	
	public void setAddress(String inDeviceAddress) {
		deviceAddress = inDeviceAddress;
	}
	
	public void setTime() {
		lastSeen.setTime(System.currentTimeMillis());
	}

	public boolean equals(Object otherObject) {
		SavedPerson otherDevice = (SavedPerson) otherObject;

		return deviceAddress.equals(otherDevice.deviceAddress);
	}

	@Override
	public int compareTo(SavedPerson other) {
		return lastSeen.compareTo(other.lastSeen);
	}
	
	public static Comparator<SavedPerson> byDeviceName() {
		return new Comparator<SavedPerson>() {
			public int compare(SavedPerson deviceA, SavedPerson deviceB) {
				String deviceAName = deviceA.name;
				String deviceBName = deviceB.name;
				
				return deviceAName.compareTo(deviceBName);
			}
		};
	}
}
